<template>
  <div class="dashboard-container">
    <aside class="aside-style">
      <el-row>
        <el-col :span="2">
          <el-button type="primary" size="mini" icon="el-icon-circle-plus" @click="addNewDriver">新增</el-button>
        </el-col>
      </el-row>
    </aside>
    <el-table
      :data="list"
      border
      highlight-current-row
      width="100%"
      style="margin-top: 20px;font-size:12px"
    >
      <el-table-column label="头像" align="center">
        <template slot-scope="scope">
          <img :src="scope.row.avatar_url" alt="" class="img-style">
        </template>
      </el-table-column>
      <el-table-column prop="user_name" label="姓名" align="center" />
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <del-confirm button-text="解除" title="是否确认解除用户司机职位？" @onConfirm="delFun(scope.row)" />
        </template>
      </el-table-column>
    </el-table>
    <pagination :total="total" pagination="paginationFun" />
    <addDialog ref="add-dialog" @reloadFun="reloadFun" />
  </div>
</template>

<script>
import pagination from '@/components/Pagination'
import delConfirm from '@/components/DelConfirm'
import addDialog from '../carControl/components/driver-dialog'
import { getDriverListApi, getDepartmentListApi, setUserUndriverApi } from '@/api/main'
export default {
  components: {
    pagination,
    delConfirm,
    addDialog
  },
  data() {
    return {
      list: [],
      total: 0,
      department: []
    }
  },
  created() {
    this.getDriverList()
    this.getDepartmentList()
  },
  methods: {
    getDepartmentList() {
      const data = {
        status: ''
      }
      getDepartmentListApi(data).then(res => {
        console.log('res', res)
        if (res.code === 200) {
          this.department = res.list
        }
      })
    },
    addNewDriver() {
      this.$refs['add-dialog'].dialogVisible = true
      this.$refs['add-dialog'].department = this.department
    },
    delFun(row) {
      console.log(row)
      setUserUndriverApi({ user_id: row.id }).then(res => {
        if (res.code === 200) {
          this.$message.success(res.msg)
          this.getDriverList()
        }
      })
    },
    getDriverList() {
      const data = {
        limit: this.limit,
        p: this.p
      }
      getDriverListApi(data).then(res => {
        console.log(res)
        this.list = res.list
        this.total = Number(res.count)
      })
    },
    reloadFun() {
      this.getDriverList()
    },
    paginationFun(val) {
      this.p = val.page
      this.limit = val.limit
      this.getDriverList()
    }
  }
}
</script>

<style lang="scss" scoped>
.img-style {
    width: 5opx;
    height:50px;
}
.dashboard {
    &-container {
        margin: 30px;
    }
    &-text {
        font-size: 30px;
        line-height: 46px;
    }
}
</style>
